package com.testmall.service.impl;

import com.testmall.common.base.BaseServiceImpl;
import com.testmall.entity.Orders;
import com.testmall.mapper.OrderitemMapper;
import com.testmall.mapper.OrdersMapper;
import com.testmall.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @Description:
 * @Author: littleDesire
 * @Date: 2022-06-21 14:29
 * @Version: 1.0
 */
@Service
public class OrdersServiceImpl extends BaseServiceImpl<Orders, OrdersMapper> implements OrdersService {
    @Autowired
    OrdersMapper ordersMapper;
    @Autowired
    OrderitemMapper orderitemMapper;


    @Transactional   //事务处理
    @Override
    public int mainsaveOrders(Orders orders) {
        String id = UUID.randomUUID().toString();
        orders.setOrderid(id);
        int rs = ordersMapper.saveOrders(orders);

        if (rs == 1) {
            List detail = orders.getDetail();
            if (null != detail && detail.size() > 0) {
                Map map = new HashMap();
                map.put("detail", detail);
                map.put("orderid", id);
                map.put("id", id);
                rs = orderitemMapper.saveOrderdetail(map);
            }

        }
        return rs;
    }

    @Override
    public List queryOrder(Map map) {
        return ordersMapper.queryOrders(map);
    }

    @Override
    public List queryOrdersDetail(String id) {
        return ordersMapper.queryOrdersDetail(id);
    }


    @Override
    public List queryCategory(Orders orders) {
        return null;
    }


    @Override
    public List querymemberCategory() {
        return ordersMapper.queryMemberOrders();
    }


}
